package edu.dkakunsi.ta.client.util;

import edu.dkakunsi.ta.client.bean.*;
import edu.dkakunsi.ta.client.entity.*;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

/**
 *
 * @author dkakunsi
 */
public class ServiceManager {

    private QName PORT_NAME;
    
    private Service getService(Object obj, String wsdlLocation) throws MalformedURLException {
        String className = obj.getClass().getSimpleName();

        final QName SERVICE_NAME = new QName(Constant.TARGET_NAMESPACE, className + "Service");
        PORT_NAME = new QName(Constant.TARGET_NAMESPACE, className + "Port");
        
        URL wsdlUrl = new URL(wsdlLocation);
        Service service = Service.create(wsdlUrl, SERVICE_NAME);
        return service;
    }

    public DepartmentWs getDepartmentService() throws MalformedURLException {
        return getService(new Department(), Constant.DEPARTMENT_WSDL).getPort(PORT_NAME, DepartmentWs.class);
    }

    public PegawaiWs getPegawaiService() throws MalformedURLException {
        return getService(new Pegawai(), Constant.PEGAWAI_WSDL).getPort(PORT_NAME, PegawaiWs.class);
    }
    
    public PresensiWs getPresensiService() throws MalformedURLException {
        return getService(new Presensi(), Constant.PRESENSI_WSDL).getPort(PORT_NAME, PresensiWs.class);
    }
    
    public IzinWs getIzinService() throws MalformedURLException {
        return getService(new Izin(), Constant.IZIN_WSDL).getPort(PORT_NAME, IzinWs.class);
    }

    public LemburWs getLemburService() throws MalformedURLException {
        return getService(new Lembur(), Constant.LEMBUR_WSDL).getPort(PORT_NAME, LemburWs.class);
    }
}
